package com.mm.controller;

import com.mm.bo.GoodsInsertBo;
import com.mm.bo.GoodsSearchBo;
import com.mm.exception.CustomException;
import com.mm.service.GoodsInfoService;
import com.mm.util.GetHeadUtil;
import com.mm.util.PageUtil;
import com.mm.util.ResultUtil;
import com.mm.vo.GoodsInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @ClassName GoodsController
 * @Description TODO
 * @Author 任昊
 * @Date 2020/12/7 12:30
 */
@Api(tags = "用于物资信息管理的接口")
@RestController
public class GoodsInfoController {

    @Resource
    private GoodsInfoService goodsInfoService;

    @ApiOperation(value = "新增物资", notes = "新增物资")
    @PostMapping("/v1/goods/insertGoods")
    public ResultUtil insertGoodsInfo(@RequestBody @Valid GoodsInsertBo goodsInsertBo){
        goodsInsertBo.setToken(GetHeadUtil.getHeadToken());
        Integer row = goodsInfoService.insertGoods(goodsInsertBo);
        if(row < 1){
            throw new CustomException("新增成功");
        }
        return ResultUtil.success(null);
    }

    @ApiOperation(value = "物资查询", notes = "物资查询")
    @PostMapping("/v1/goods/selectGoods")
    public ResultUtil<Object> selectGoodsInfo(@RequestBody @Valid GoodsSearchBo goodsSearchBo){
        PageUtil<GoodsInfoVo> pageUtil = goodsInfoService.selectGoods(goodsSearchBo);
        return ResultUtil.success(pageUtil);
    }
}
